<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8"
	import="java.util.*,com.unitedats.HR.Entity.*,com.unitedats.Project.Entity.*,com.unitedats.common.util.*,com.unitedats.HR.Entity.HrEmployee"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Project</title>
</head>
<body>
	<form id="projectForm" action="ProjectProcess" method="post" enctype="multipart/form-data">
		<table class="layout_grid">
			<tr>
				<td colspan="2"><h1 class="page_title">Project Details</h1></td>
			</tr>
			<tr>
				<td class="side_label_middle">Project Name :</td>
				<td><input name="name" type="text" id="name" size="50" required></td>
			</tr>
			<tr>
				<td class="side_label_middle">Project Code :</td>
				<td><input name="code" type="text" id="code" size="20" required></td>
			</tr>
			<tr>
				<td class="side_label_middle">Project Country :</td>
				<td>
					<select name="country" id="country" required>
							<%
							if (request.getAttribute("countryList")!=null){
								for (LookupCountry country : (List<LookupCountry>)request.getAttribute("countryList")){
							%>
									<option value="<%=country.getId()%>"><%=country.getName()%></option>
							<%}}%>
					</select>
				</td>
			</tr>
			<tr>
				<td class="side_label_middle">Project Type :</td>
				<td><%=HtmlUtil.drawProjectTypeList("ptype")%></td>
			</tr>
			<tr>
				<td class="side_label_middle">Project Status :</td>
				<td><%=HtmlUtil.drawProjectStatusList("status")%></td>
			</tr>
			<script>
			 $("input[name='ptype']").prop("required",true);
			 $("input[name='status']").prop("required",true);
			</script>
			<tr>
				<td class="side_label_middle">Planned Start Date :</td>
				<td><input type="text" name="plannedStartDate"
					id="plannedStartDate" class="caldr"></td>
			</tr>
			<tr>
				<td class="side_label_middle">Planned End Date :</td>
				<td><input type="text" name="plannedEndDate"
					id="plannedEndDate" class="caldr"></td>
			</tr>
			<tr>
				<td class="side_label_middle">Actual Start Date :</td>
				<td><input type="text" name="actualStartDate"
					id="actualStartDate" class="caldr"></td>
			</tr>
			<tr>
				<td class="side_label_middle">Actual End Date :</td>
				<td><input type="text" name="actualEndDate" id="actualEndDate"
					class="caldr"></td>
			</tr>

			<tr>
				<td colspan="2" class="subtitle">Partner Details :</td>
			</tr>
			<tr>
				<td colspan=2 "><table class="details_container" id="parteners"></table></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2" class="subtitle">Teamwork Details :</td>
			</tr>
			<tr>
				<td colspan="2"><table class="details_container" id="teamwork">
					</table></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td class="side_label_middle">Total Contract Value :</td>
				<td><input type="text" name="totalContractValue"
					id="totalContractValue" data-rule-number="true"> <select name="currency"
					id="currency" class="auto_off">
						<%
							if (request.getAttribute("currencyList")!=null) {
										        for (LookupCurrency currency : (List<LookupCurrency>)request.getAttribute("currencyList")){
						%>
						<option value="<%=currency.getId()%>"><%=currency.getName()%></option>
						<%}}%>
				</select></td>
			</tr>
			<tr>
				<td class="side_label_top">Contract File :</td>
				<td><input type="file" name="contractFileUrl"
					id="contractFileUrl" multiple></td>
			</tr>
			<tr>
				<td class="side_label_top">PO Document :</td>
				<td><input type="file" name="poUrl" id="poUrl" multiple></td>
			</tr>
			<tr>
				<td class="side_label_middle">Contract Number :</td>
				<td><input type="text" name="contractNumber"
					id="contractNumber"></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" value="save"></td>
			</tr>
		</table>
	</form>
	<script type="text/javascript">

<%
PmProject pr = (PmProject) request.getAttribute("project");

StringBuffer countryListStr =  new StringBuffer();
if (request.getAttribute("countryList") !=null){
   for (LookupCountry c : (List<LookupCountry>)request.getAttribute("countryList"))
       countryListStr.append(c.getId() +": '"+c.getName()+"' , "); 
}

StringBuffer empListStr =  new StringBuffer();
if (request.getAttribute("empList") !=null){
   for (HrEmployee emp : (List<HrEmployee>)request.getAttribute("empList")){
	   empListStr.append(emp.getId() +": '"+emp.getNameEn()+"' , "); 
   }
}

int partnersInitRows = 0;
if (pr!=null && pr.getPmProjectPartnerList()!=null)
   partnersInitRows = pr.getPmProjectPartnerList().size();

int teamworkInitRows = 0;
if (pr!=null&&  pr.getPmProjectMemberList()!= null )
   teamworkInitRows = pr.getPmProjectMemberList().size();
   
%>

$(function(){  
         
        // Initialize appendGrid
        $('#parteners').appendGrid({
            initRows: <%=partnersInitRows%>,
            i18n: {rowEmpty: 'No Parteners Assigned'},
            columns: [
			           { name: 'name', display: 'Name', type: 'text', ctrlAttr: { minlength: 100 } ,  ctrlAttr: { maxlength: 100 }, ctrlCss: { display:'block', width:'300px', margin:'auto', 'font-size':'.9em'} , ctrlClass: 'required' },
			           { name: 'country', display: 'Country', type: 'select', ctrlOptions: {<%=countryListStr.toString()%>}, ctrlCss: { display:'block', margin: 'auto', 'font-size':'.9em'} , ctrlClass: 'required' }
                     ]
        });    
     

       $('#teamwork').appendGrid({
            initRows: <%=teamworkInitRows%>,
            i18n: {rowEmpty: 'Nobody Added To Teamwork'},
            columns: [
	                   { name: 'name', display: 'Name', type: 'select', ctrlOptions: {<%=empListStr.toString()%>}, ctrlCss: { display:'block', margin: 'auto', 'font-size':'.9em'} , ctrlClass: 'required' },
	                   { name: 'role', display: 'Role', type: 'text', ctrlAttr: { maxlength: 100 }, ctrlCss: { display:'block', width: '200px', margin: 'auto', 'font-size':'.9em'} , ctrlClass: 'required' }
                     ]
        }); 
		
		//$.validator.addClassRule('roleName' {required : true , number : true} )
		
		 	  

<%if (pr != null) {%>
    appendIdElement("pId","<%=pr.getId()%>");
    setTextFieldValue("name","<%=Common.getDisplayString(pr.getName(),"")%>");     
    setTextFieldValue("code","<%=Common.getDisplayString(pr.getCode(),"")%>");     
    setComboSelectedValue("country","<%=(pr.getCountryId() != null)?pr.getCountryId().getId():""%>");
    setRadioCheckedValue("status","<%=pr.getStatusId()%>");
    setRadioCheckedValue("ptype","<%=pr.getTypeId()%>");
    setDateValue("plannedStartDate","<%=DateUtil.getDateString(pr.getPlannedStartDate())%>");	
    setDateValue("plannedEndDate","<%=DateUtil.getDateString(pr.getPlannedEndDate())%>");	
    setDateValue("actualStartDate","<%=DateUtil.getDateString(pr.getActualStartDae())%>");	
    setDateValue("actualEndDate","<%=DateUtil.getDateString(pr.getActualEndDate())%>");	
    setTextFieldValue("totalContractValue" , "<%=Common.getDisplayString(pr.getTotalContractValue(),"")%>");
    setComboSelectedValue("currency","<%=(pr.getContractCurrentcyId() != null)?pr.getContractCurrentcyId().getId():""%>");
 	showUploadedFilesList("contractFileUrl", <%=HtmlUtil.arrayFromJavaToJavaScript(pr.getContractFileUrl())%>);
 	showUploadedFilesList("poUrl", <%=HtmlUtil.arrayFromJavaToJavaScript(pr.getPoUrl())%>);
 	setTextFieldValue("contractNumber" , "<%=Common.getDisplayString(pr.getContractNo(),"")%>");
    
  <%for (int i = 0 ; i < partnersInitRows;  i++){%>
    setTextFieldValue("parteners_name_<%=i+1%>","<%=pr.getPmProjectPartnerList().get(i).getName()%>");
    setComboSelectedValue("parteners_country_<%=i+1%>","<%=pr.getPmProjectPartnerList().get(i).getCountryId().getId()%>");
 <%}%> 
 
 <%for (int i = 0 ; i < teamworkInitRows;  i++){%>
    setComboSelectedValue("teamwork_name_<%=i+1%>", "<%=pr.getPmProjectMemberList().get(i).getEmpId().getId()%>");
 	setTextFieldValue("teamwork_role_<%=i+1%>","<%=pr.getPmProjectMemberList().get(i).getRole()%>");
 <%}%>
 
	
<%}%>	


	//$("input[name='ptype']").rules("add",{required:true});
	//$("input[name='status']").rules("add",{required:true});
	
	$("#plannedEndDate" ).rules( "add", {
		dateGreaterThan: ['#plannedStartDate'],
		messages: {	dateGreaterThan: "planned end date must greater than planned start date"}
	});
	
	
	$("#actualEndDate" ).rules( "add", {
		dateGreaterThan: ['#actualStartDate'],
		messages: {	dateGreaterThan: "actual end date must greater than actual start date"}
	});


});

</script>
</body>
</html>